<?php
// This view is showing all users in the database.


echo heading("All Users",2);

//Initializing table for structure of users.
$TABLE = array();

//Checking if the database contain any users.
if (count($results))
    {
        //Creates a link by name-string, an image, a follow-link and a 'friendrequest-link' for each user, exept the 'logged_in_user'.
	foreach ($results as $id => $person)
        {
            $string = anchor("users/home/".$person->id,$person->first_name . " ". $person->last_name);
            $string .= br();

            $properties = array(
                                    'src' => 'users/get_photo/'. $person->id,
                                    'width' => '120',
                                    'height' => '110'
            );
            $string .= img($properties,true);

            $properties = array();
            $string .= br();

            //Checks the 'following'-logic
            if ($person->id != $this->session->userdata('id'))
            {
                if (in_array($person->id,$following))
                {
                    $string .= anchor("users/unfollow/".$person->id, "<small>stop following</small>");
                    $string .= br();
                }
                else
                {
                    $string .= anchor("users/follow/".$person->id, "<small>follow status updates</small>");
                    $string .= br();
                }
            }

            //Checks the 'friends'-logic
            if ($person->id != $this->session->userdata('id'))
            {
                if (in_array($person->id,$friends))
                {
                    $string .= anchor("users/delete_friend/".$person->id, "<small>remove as friend</small>");
                    $string .= br(2);
                }
                else
                {
                    $string .= anchor("users/send_friend_request/".$person->id, "<small>send friend request</small>");
                    $string .= br(2);
                }
            }
            
    
            $TABLE[] = $string;
    }

    //Structuring the table, so the result looks pretty, using the CI_table
    $tmpl = array (
            'table_open'  => "<table class='grid'>",
            'row_start'   => "<tr valign='top'>",
    );
    $this->table->set_template($tmpl);
    $this->table->set_empty("&nbsp;");
    $pretty = $this->table->make_columns($TABLE,4);

    echo $this->table->generate($pretty);



}else{
	echo "Sorry, no search results matched that query!";
}


